Bask

Shanghai Based Android Engineer currently develop Payment systems at Ctrip

👨‍🔧‍

Flutter-Android开发者文档 -布局

By Bask on null

This post is over a year old. Some of the content may be out of date.

喜欢我的小伙伴,一定要关注我的微信公众号啊!!!谢谢啦 AllAboutCoding AllAboutCoding

此文章为翻译Flutter官网的Flutter for Android Developers - Layout有兴趣的小伙伴可以移步官网查看。

Layout

Flutter中的LinearLayout是什么?

在Android中,LinearLayout通常将Widget线性(水平或者垂直)的放置。在Flutter中,使用Row Widget或者Column Widget来达到这一目标。 如果你注意到这两个例子的话有一个例外,就是使用“Row”或者“Column” Widget。子Widget相同并且并且这一功能可以被开发丰富的布局,可以后改变相同的子Widget。


Widget build(BuildContext context) {
  return new Row(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
      new Text('Row One'),
      new Text('Row Two'),
      new Text('Row Three'),
      new Text('Row Four'),
    ],
  );
}

Widget build(BuildContext context) {
  return new Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
      new Text('Column One'),
      new Text('Column Two'),
      new Text('Column Three'),
      new Text('Column Four'),
    ],
  );
}

Flutter中的RelativeLayout是什么?

RelativeLayout可以让Widget之间相对放置,在Flutter中,可以使用几种方法来达到相同的效果。 你可以使用Column,Row,Stack Widget的组合来达到RelativeLayout的效果。你可以给Widget定制特别的规则,比如子Widget如何相对放置于父Widget。 在Flutter中创建一个好的RelativeLayout的例子,请在StackOverFlow看Collin的回答。

Flutter中的ScrollView是什么?

在Android中,如果用户的屏幕小于你的内容,就需要使用ScrollView放置你的Widget,他就会滚动。 在Flutter中,最简单的方法是使用ListView Widget。在Android中,这可能看起来有点大材小用,但是在Flutter中,ListView Widget就是ScrollView和Android ListView。


Widget build(BuildContext context) {
  return new ListView(
    children: <Widget>[
      new Text('Row One'),
      new Text('Row Two'),
      new Text('Row Three'),
      new Text('Row Four'),
    ],
  );
}

Flutter中如何处理场景转换?

如果AndroidManifest.xml中包含的话,FlutterView就可以处理这些配置:

android:configChanges="orientation|screenSize"